<template>
	<view class="content">
		<!-- F1: 状态栏 -->
		<myStatusbar />
		<!-- F2: 自定义导航栏 -->
		<uni-nav-bar 
			title="缴费"
			leftIcon="back"
			leftText="返回"
			rightIcon="list"
			backgroundColor="#090"
			color="#FFF"
			@clickLeft="goBack"
			@clickRight="jump('/pages/feeRecord/feeRecord')"
		/>
		<!-- F3: 累计费用 -->
		<view class="fee-statistics">
			<text class="hint">当前待缴费用（元）</text>
			<!-- toFixed 保留小数点后n位 -->
			<text class="amount">{{amount.toFixed(2)}}</text>
		</view>
		<!-- F4: 各项费用列表 -->
		<uni-list>
			<uni-list-item 
				title="水费"
				thumb="/static/img/shui.png"
				thumbSize="lg"
				link="navigateTo"
				to="/pages/feePay/feePay?type=1"
				:rightText="fees.shui<0 ? `待缴：${-fees.shui}` : ''"
			></uni-list-item>
			<uni-list-item
				title="电费"
				thumb="/static/img/dian.png"
				thumbSize="lg"
				link="navigateTo"
				to="/pages/feePay/feePay?type=2"
				:rightText="fees.dian<0 ? `待缴：${-fees.dian}` : ''"
			></uni-list-item>
			<uni-list-item
				title="燃气费"
				thumb="/static/img/ranqi.png"
				thumbSize="lg"
				link="navigateTo"
				to="/pages/feePay/feePay?type=3"
				:rightText="fees.ranqi<0 ? `待缴：${-fees.ranqi}` : ''"
			></uni-list-item>
			<uni-list-item
				title="物业费"
				thumb="/static/img/wuye.png"
				thumbSize="lg"
				link="navigateTo"
				to="/pages/feePay/feePay?type=4"
				:rightText="fees.wuye<0 ? `待缴：${-fees.wuye}` : ''"
			></uni-list-item>
			<uni-list-item
				title="停车费"
				thumb="/static/img/parking.png"
				thumbSize="lg"
				link="navigateTo"
				to="/pages/feePay/feePay?type=5"
				:rightText="fees.tingche<0 ? `待缴：${-fees.tingche}` : ''"
			></uni-list-item>
			<uni-list-item
				title="宽带费"
				thumb="/static/img/kuandai.png"
				thumbSize="lg"
				link="navigateTo"
				to="/pages/feePay/feePay?type=6"
				:rightText="fees.kuandai<0 ? `待缴：${Math.abs(fee.kuandai)}` : ''"
			></uni-list-item>
		</uni-list>
	</view>
</template>

<script>
import { feeList } from '../../service'
	export default {
		data() {
			return {
				fees: {}  // 保存各项费用信息
			}
		},
		async onLoad() {
			// 当页面组件挂载后，请求接口
			const data = await feeList()
			console.log(data)
			this.fees = data
		},
		methods: {
			goBack() {
				uni.navigateBack()
			},
			jump(url) {
				uni.navigateTo({
					url
				})
			},
		},
		// 计算属性
		computed: {
			// 定义方法名称
			amount() {
				// 一旦各项费用发生变化，会自动计算
				var sum = 0 //保存待缴总和
				if(this.fees.shui<0) sum+=this.fees.shui
				if(this.fees.dian<0) sum+=this.fees.dian
				if(this.fees.ranqi<0) sum+=this.fees.ranqi
				if(this.fees.wuye<0) sum+=this.fees.wuye
				if(this.fees.tingche<0) sum+=this.fees.tingche
				if(this.fees.kuandai<0) sum+=this.fees.kuandai
				return -sum
			}
		}
	}
</script>

<style lang="scss" scoped>
	.uni-navbar {
		display: block;
		// ::v-deep 样式穿透
		::v-deep .uni-navbar__content {
			display: block;
		}
	}
	.fee-statistics {
		background-color: $zh-theme-color;
		color: $zh-theme-color-inverse;
		flex-direction: column;
		align-items: center;
		padding: $uni-spacing-col-lg*3 0;
		.hint {
			font-size: $uni-font-size-lg;
		}
		.amount {
			font-size: $uni-font-size-lg*2.2;
			margin-top: $uni-spacing-col-base;
		}
	}
</style>
